package com.snowleopard.common.tags;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.components.Component;
import org.apache.struts2.views.jsp.ui.AbstractUITag;
import org.springside.modules.orm.Page;

import com.opensymphony.xwork2.util.ValueStack;

/*
 * @(#)PageTag.java 1.0 09/11/20
 * 
 * Copyright (c) 2009 Accentrix IT Consulting. All Rights Reserved.
 */
/**
 * 分页的tag
 * 
 * @author vincent.chen
 * 
 */
public class PageTag extends AbstractUITag {

	private static final long serialVersionUID = 1L;

	private String page;

	@Override
	public Component getBean(ValueStack valueStack, HttpServletRequest request, HttpServletResponse respose) {
		return new Paging(valueStack, request, respose);
	}

	@Override
	protected void populateParams() {
		super.populateParams();

		HttpServletRequest request = ServletActionContext.getRequest();
		String ctx = request.getContextPath();

		Paging paging = (Paging) component;

		paging.setPage((Page<?>) findValue(page));
		paging.setCtx(ctx);

	}

	public void setPage(String page) {
		this.page = page;
	}

}
